<?php

namespace App\Http\ViewComposers;

use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Auth;
use Illuminate\Database\Eloquent\Collection;
use App\User;
use App\Models\CompanyJobs;
use App\Models\CompanyFolder;
use App\Models\Company;
/**
 *
 * @author xiadx
 *
 */
class CompanyCenterComposer
{
    /**
     * 中心企业 菜单
     * @var arrray
     */
    protected $company_menu;

    /**
     * 当前登陆用户
     * @var Collection
     */
    protected $userinfo;

    protected $jobscount;
    
    protected $resumecount;
    protected $baidukey;
    protected $company;
    
    public function __construct()
    {
        $user = Auth::user();
        $this->company_menu = Config::get('company');
        $this->userinfo = User::find($user->id);
        $this->userinfo->middle_logo = userlogo($user->id,'middle');
        if($this->userinfo->company_id > 0)
        {
            $this->company = Company::find($this->userinfo->company_id);
            $this->jobscount = CompanyJobs::where('company_id','=',$this->userinfo->company_id)->count();
            $this->resumecount = CompanyFolder::where('company_id','=',$this->userinfo->company_id)->count();
        }
        else
        {
            $this->jobscount = $this->resumecount = 0;
        }
        $this->baidukey = Config::get('app.baidukey');
    }

    public function compose(View $view)
    {
        $view->with('company_menu',$this->company_menu);
        $view->with('userinfo',$this->userinfo);
        $view->with('jobscount',$this->jobscount);
        $view->with('resumecount',$this->resumecount);
        $view->with('baidukey',$this->baidukey);
        $view->with('mycompany',$this->company);
    }
    
}